<?php
/**
 * Created by PhpStorm.
 * User: yuyiwen
 * Date: 2018/10/26
 * Time: 上午9:45
 */

namespace app\admin\controller;


use think\Request;

class Member extends Common
{
    public function index ()
    {
        // 判断用户是否有搜索
        $search = input('get.search' , '' , 'htmlspecialchars');
        $ad = db('member');
        $config = [];
        if ($search != '')
        {
            $config = ['query'=>['search' =>$search ]];

            $ad
                ->whereLike('name' , "%{$search}%" , 'or')
                ->whereLike('phone' , "%{$search}%",'or')
                ->whereLike('certificate' , "%{$search}%",'or')
                ->whereLike('card' , "%{$search}%",'or');

        }

        $ad_list =$ad->paginate(10 , false , $config);
        $page  = $ad_list->render();
        $search = ['pagination' , 'disabled' , 'active'];
        $replace = ['am-pagination tpl-pagination' , 'am-disabled' , 'am-active'];
        $page = str_replace($search , $replace , $page);

        $request = Request::instance();
        if ($request -> isAjax()) {
            return json(['ad_list' => $ad_list , 'page' => $page]);
        }else {
            $this->assign('page', $page);
            $this->assign('ad_list', $ad_list);
            return view();
        }
    }
}